<!DOCTYPE html>
<html>
<head>
	<title>Custom DOM events</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<style>
		div#simpleLog {
			width: 500px;
			height: 200px;
			font-family: Roboto, Arial, Helvetica;
			font-size: 14px;
			color: #404040;
			overflow: auto;
		}
		span.allow {
			color: green;
		}
		span.deny {
			color: red;
		}
	</style>
	<script>
		var myForm, formData, logObj;
		function doOnLoad() {
			formData = [
				{type: "settings", position: "label-left", labelWidth: "100"},
				{type: "input", name: "login", value: "abc", label: "Login"},
				{type: "input", name: "email", value: "abc@mail.com", label: "E-mail"},
				{type: "calendar", name: "birthday", value: "1980-05-27", label: "Birthday", dateFormat: "%Y-%m-%d", calendarPosition: "right"},
				{type: "colorpicker", name: "favcolor", value: "#2391E9", label: "Fav. Color"}
				
			];
			myForm = new dhtmlXForm("myForm", formData);
			
			// adding custom blur event, w/o overwriting existing
			var inpLogin = myForm.getInput("login");
			if (window.addEventListener) {
				inpLogin.addEventListener("blur",doOnBlur,false);
			} else {
				inpLogin.attachEvent("onblur",doOnBlur);
			}
			
			// adding custom blur event, with overwriting existing
			var inpEmail = myForm.getInput("email");
			inpEmail.onblur = doOnBlur;
			
			// custom click event
			var inpCalendar = myForm.getInput("birthday");
			if (window.addEventListener) {
				inpCalendar.addEventListener("click",doOnClick,false);
			} else {
				inpCalendar.attachEvent("onclick",doOnClick);
			}
		}
		function doOnBlur(e){
			e = e||event;
			var t = (e.target||e.srcElement);
			logEvent("custom onblur event: "+t._idd+"<br>");
		}
		function doOnClick(e){
			e = e||event;
			var t = (e.target||e.srcElement);
			logEvent("custom onclick event: "+t._idd+"<br>");
		}
		function logEvent(t) {
			if (!logObj) logObj = document.getElementById("simpleLog");
			logObj.innerHTML += t;
			logObj.scrollTop = logObj.scrollHeight;
		}
		function clearLog() {
			if (!logObj) logObj = document.getElementById("simpleLog");
			logObj.innerHTML = "";
		}
	</script>
</head>
<body onload="doOnLoad();">
	<table>
		<tr><td><div id="myForm"></div></td></tr>
		<tr><td><b>Log (<a href="javascript:void(0);" onclick="clearLog();">clear</a>)</b></td></tr>
		<tr><td><div id="simpleLog"></div></td></tr>
	</table>
</body>
</html>